//
//  HWMyInformationCell.m
//  嗨文
//
//  Created by 响当当 on 2019/1/11.
//  Copyright © 2019年 dongzheng. All rights reserved.
//

#import "HWMyInformationCell.h"

@interface HWMyInformationCell()
@property (nonatomic, strong)UIImageView *iconImageView;//icon
@property (nonatomic, strong)UILabel *titleLabel;//标题
@property (nonatomic, strong)UILabel *subTitleLabel;//副标题
@property (nonatomic, strong)UILabel *levelLabel;//等级
@property (nonatomic, strong)UIView *lineView;//下划线
@property (nonatomic, strong)UILabel *subLabel;//副标示
@end

@implementation HWMyInformationCell

- (UIImageView *)iconImageView
{
    if (!_iconImageView)
    {
        _iconImageView = [[UIImageView alloc]initWithFrame:CGRectMake(15*kUIScaleBasePlus,24*kUIScaleBasePlus,21*kUIScaleBasePlus,18*kUIScaleBasePlus)];
    }
    return _iconImageView;
}

- (UILabel *)titleLabel
{
    if (!_titleLabel)
    {
        _titleLabel = [HWUtilties creatLabelWithFrame:CGRectMake(CGRectGetMaxX(self.iconImageView.frame)+20*kUIScaleBasePlus,0,200*kUIScaleBasePlus,15*kUIScaleBasePlus)
                                         textAligment:NSTextAlignmentLeft
                                             textClor:LCHexColor(0x212121)
                                             textFont:16*kUIScaleBasePlus];
    }
    return _titleLabel;
}

- (UILabel *)subTitleLabel
{
    if (!_subTitleLabel)
    {
        _subTitleLabel = [HWUtilties creatLabelWithFrame:CGRectMake(CGRectGetMaxX(self.iconImageView.frame)+20*kUIScaleBasePlus,0,200*kUIScaleBasePlus,12*kUIScaleBasePlus)
                                         textAligment:NSTextAlignmentLeft
                                             textClor:LCHexColor(0x828282)
                                             textFont:12*kUIScaleBasePlus];
    }
    return _subTitleLabel;
}

- (UILabel *)subLabel
{
    if (!_subLabel)
    {
        _subLabel = [HWUtilties creatLabelWithFrame:CGRectMake(SCREEN_WIDTH - 70*kUIScaleBasePlus-10*kUIScaleBasePlus,15*kUIScaleBasePlus,60*kUIScaleBasePlus,30*kUIScaleBasePlus)
                                       textAligment:NSTextAlignmentCenter
                                           textClor:[UIColor whiteColor]
                                           textFont:12*kUIScaleBasePlus];
        _subLabel.layer.masksToBounds = YES;
        _subLabel.layer.cornerRadius = 5;
        
        _subLabel.hidden = YES;
    }
    return _subLabel;
}

- (UILabel *)levelLabel
{
    if (!_levelLabel)
    {
        _levelLabel = [HWUtilties creatLabelWithFrame:CGRectMake(CGRectGetMaxX(self.titleLabel.frame)+13*kUIScaleBasePlus,0,60*kUIScaleBasePlus,10*kUIScaleBasePlus)
                                         textAligment:NSTextAlignmentLeft
                                             textClor:LCHexColor(0xF54337)
                                             textFont:13*kUIScaleBasePlus];
    }
    return _levelLabel;
}

- (UIView *)lineView
{
    if (!_lineView)
    {
        _lineView = [[UIView alloc] initWithFrame:CGRectMake(52*kUIScaleBasePlus,63*kUIScaleBasePlus,308*kUIScaleBasePlus,1*kUIScaleBasePlus)];
        _lineView.backgroundColor = LCHexColor(0xEBE5E1);
    }
    return _lineView;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
        [self.contentView addSubview:self.iconImageView];
        [self.contentView addSubview:self.titleLabel];
        [self.contentView addSubview:self.subTitleLabel];
        [self.contentView addSubview:self.subLabel];
//        [self.contentView addSubview:self.levelLabel];
        [self.contentView addSubview:self.lineView];
    }
    return self;
}

#pragma mark - 获取数据
- (void)getInfo:(NSDictionary *)model indexPathRow:(NSInteger)row
{
    
    self.titleLabel.text = model[@"title"];
    [self.titleLabel sizeToFit];
    
    self.iconImageView.image = [UIImage imageNamed:model[@"icon"]];
    
    if ([current_User.isHideinfo.stringValue isEqualToString:@"0"])
    {
        switch (row)
        {
            case 0:
            {
                self.subLabel.hidden = NO;
                self.subLabel.text = @"去收徒";
                self.subLabel.backgroundColor = LCHexColor(0x1ba3e5);
            }
                break;
            case 1:
            {
                self.subLabel.hidden = NO;
                self.subLabel.text = @"领书券";
                self.subLabel.backgroundColor = JSAMainColor;
            }
                break;
            case 2:
            {
                self.subLabel.hidden = NO;
                self.subLabel.text = @"去收集";
                self.subLabel.backgroundColor = JSAMainColor;
            }
                break;
            default:
            {
                self.subLabel.hidden = YES;
            }
                break;
        }
    }
    else
    {
        self.subLabel.hidden = YES;
    }
    
    if ([model[@"subTitle"] isValidString])
    {
        [self.titleLabel setY:15*kUIScaleBasePlus];
        [self.subTitleLabel setX:CGRectGetMaxX(self.iconImageView.frame)+20*kUIScaleBasePlus];
        [self.subTitleLabel setY:CGRectGetMaxY(self.titleLabel.frame)+5*kUIScaleBasePlus];
        self.subTitleLabel.text = model[@"subTitle"];
        [self.subTitleLabel sizeToFit];
        
        if ([model[@"level"] isValidString])
        {
            [self.levelLabel setX:CGRectGetMaxX(self.titleLabel.frame)+13*kUIScaleBasePlus];
            [self.levelLabel setY:20*kUIScaleBasePlus];
            self.levelLabel.text = model[@"level"];
            [self.levelLabel sizeToFit];
            
        }
    }
    else
    {
        [self.titleLabel setY:25*kUIScaleBasePlus];
        [self.subTitleLabel setFrame:CGRectZero];
        [self.levelLabel setFrame:CGRectZero];
    }
    
}
@end
